package com.jf.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-09-02
 * Time:22:42
 */
@WebServlet(name = "CheckServlet", urlPatterns = "/checkServlet")
public class CheckServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if (username != null && password != null) {
            if (username.equals("admin") && password.equals("123456")) {
                HttpSession session = req.getSession();
                session.setAttribute("username", username);
                req.getRequestDispatcher("/manage/admin.jsp").forward(req, resp);
            }
        }
        String contextPath = req.getContextPath();
        resp.sendRedirect(contextPath + "/login.jsp");

    }
}
